﻿
Imports std
Imports locks

Public Module asyncmodel
    Public Function begin(ByVal action As callbackAction) As Boolean
        Return resolve(Of icallbackManager).begin(action)
    End Function

    Public Sub assert_begin(ByVal action As callbackAction)
        assert(begin(action))
    End Sub

    Public Function begin(ByVal ec As eventComb, ByVal timeoutMs As Int64) As Boolean
        Return resolve(Of eventDriver)().begin(ec, timeoutMs)
    End Function

    Public Function begin(ByVal ec As eventComb) As Boolean
        Return resolve(Of eventDriver)().begin(ec)
    End Function

    Public Sub assert_begin(ByVal ec As eventComb, ByVal timeoutMs As Int64)
        assert(begin(ec, timeoutMs))
    End Sub

    Public Sub assert_begin(ByVal ec As eventComb)
        assert(begin(ec))
    End Sub

    Public Function [goto](ByVal [step] As Int64) As Boolean
        Return eventComb.goto([step])
    End Function

    Public Function goback() As Boolean
        Return eventComb.goback()
    End Function

    Public Function goto_prev() As Boolean
        Return eventComb.goto_prev()
    End Function

    Public Function goto_end() As Boolean
        Return eventComb.goto_end()
    End Function

    Public Function goto_next() As Boolean
        Return eventComb.goto_next()
    End Function

    Public Function goto_last() As Boolean
        Return eventComb.goto_last()
    End Function

    Public Function goto_begin() As Boolean
        Return eventComb.goto_begin()
    End Function

    Public Function waitfor(ByVal ec As eventComb, ByVal timeoutMs As Int64) As Boolean
        Return eventComb.waitfor(ec, timeoutMs)
    End Function

    Public Sub assert_waitfor(ByVal ec As eventComb, ByVal timeoutMs As Int64)
        assert(waitfor(ec, timeoutMs))
    End Sub

    Public Function waitfor(ByVal ec As eventComb) As Boolean
        Return eventComb.waitfor(ec)
    End Function

    Public Sub assert_waitfor(ByVal ec As eventComb)
        assert(waitfor(ec))
    End Sub

    Public Function waitone(ByVal ParamArray ecs() As eventComb) As Boolean
        Return eventComb.waitone(ecs)
    End Function

    Public Sub assert_waitone(ByVal ParamArray ecs() As eventComb)
        assert(waitone(ecs))
    End Sub

    Public Function waitfor(ByVal action As callbackAction, ByVal timeoutMs As Int32) As Boolean
        Return eventComb.waitfor(action, timeoutMs)
    End Function

    Public Sub assert_waitfor(ByVal action As callbackAction, ByVal timeoutMs As Int32)
        assert(waitfor(action, timeoutMs))
    End Sub

    Public Function waitfor(ByVal action As callbackAction) As Boolean
        Return eventComb.waitfor(action)
    End Function

    Public Sub assert_waitfor(ByVal action As callbackAction)
        assert(waitfor(action))
    End Sub

    Public Function waitfor(ByVal ParamArray ecs() As eventComb) As Boolean
        Return eventComb.waitfor(ecs)
    End Function

    Public Sub assert_waitfor(ByVal ParamArray ecs() As eventComb)
        assert(waitfor(ecs))
    End Sub

    Public Function waitfor(ByRef cb As void) As Boolean
        Return eventComb.waitfor(cb)
    End Function

    Public Sub assert_waitfor(ByRef cb As void)
        assert(waitfor(cb))
    End Sub

    Public Function waitfor(ByVal [try] As _do(Of Boolean), ByVal timeoutMs As Int32) As Boolean
        Return eventComb.waitfor([try], timeoutMs)
    End Function

    Public Sub assert_waitfor(ByVal [try] As _do(Of Boolean), ByVal timeoutMs As Int32)
        assert(waitfor([try], timeoutMs))
    End Sub

    Public Function waitfor(ByVal [try] As _do(Of Boolean)) As Boolean
        Return eventComb.waitfor([try])
    End Function

    Public Sub assert_waitfor(ByVal [try] As _do(Of Boolean))
        assert(waitfor([try]))
    End Sub

    Public Function waitfor(ByVal ms As Int64) As Boolean
        Return eventComb.waitfor(ms)
    End Function

    Public Sub assert_waitfor(ByVal ms As Int64)
        assert(waitfor(ms))
    End Sub

    Public Function waitfor(ByVal l As lockWrapper(Of eventCombLock)) As Boolean
        Return eventComb.waitfor(l)
    End Function

    Public Sub assert_waitfor(ByVal l As lockWrapper(Of eventCombLock))
        assert(waitfor(l))
    End Sub

    Public Function waitfor(Of T)(ByVal l As multilock(Of eventCombLock), ByVal i As T) As Boolean
        Return eventComb.waitfor(l, i)
    End Function

    Public Sub assert_waitfor(Of T)(ByVal l As multilock(Of eventCombLock), ByVal i As T)
        assert(waitfor(l, i))
    End Sub

    Public Function chain_before(ByVal d As _do(Of Boolean),
                                 ByVal c As _do(Of eventComb),
                                 Optional ByVal accept_null_ec As Boolean = False) As eventComb
        Return eventComb.chain_before(d, c, accept_null_ec)
    End Function

    Public Function chain_before(ByVal d As _do(Of Boolean),
                                 ByVal ec As eventComb,
                                 Optional ByVal accept_null_ec As Boolean = False) As eventComb
        Return eventComb.chain_before(d, ec, accept_null_ec)
    End Function

    Public Function chain_after(ByVal c As _do(Of eventComb),
                                ByVal d As _do(Of Boolean),
                                Optional ByVal accept_null_ec As Boolean = False) As eventComb
        Return eventComb.chain_after(c, d, accept_null_ec)
    End Function

    Public Function chain_after(ByVal ec As eventComb,
                                ByVal d As _do(Of Boolean),
                                Optional ByVal accept_null_ec As Boolean = False) As eventComb
        Return eventComb.chain_after(ec, d, accept_null_ec)
    End Function

    Public Function chain_after(ByVal c As _do(Of eventComb),
                                ByVal before As _do(Of Boolean),
                                ByVal after As _do(Of Boolean),
                                Optional ByVal accept_null_ec As Boolean = False) As eventComb
        Return eventComb.chain_after(c, before, after, accept_null_ec)
    End Function

    Public Function chain_after_always(ByVal c As _do(Of eventComb),
                                       ByVal d As _do(Of Boolean),
                                       Optional ByVal accept_null_ec As Boolean = False) As eventComb
        Return eventComb.chain_after_always(c, d, accept_null_ec)
    End Function

    Public Function chain_after_always(ByVal ec As eventComb,
                                       ByVal d As _do(Of Boolean),
                                       Optional ByVal accept_null_ec As Boolean = False) As eventComb
        Return eventComb.chain_after_always(ec, d, accept_null_ec)
    End Function

    Public Function chain(ByVal before As _do(Of Boolean),
                          ByVal cs As _do(Of Int64, eventComb, Boolean, Boolean),
                          ByVal after As _do(Of Boolean)) As eventComb
        Return eventComb.chain(before, cs, after)
    End Function

    Public Function chain(ByVal cs As _do(Of Int64, eventComb, Boolean, Boolean)) As eventComb
        Return eventComb.chain(cs)
    End Function

    Public Function chain(ByVal ParamArray cs() As pair(Of _do(Of eventComb), Boolean)) As eventComb
        Return eventComb.chain(cs)
    End Function

    Public Function chain(ByVal ParamArray cs() As void(Of eventComb, Boolean)) As eventComb
        Return eventComb.chain(cs)
    End Function

    Public Function chain(ByVal accept_null_ec As Boolean,
                          ByVal ParamArray cs() As _do(Of eventComb)) As eventComb
        Return eventComb.chain(accept_null_ec, cs)
    End Function

    Public Function chain(ByVal before As _do(Of Boolean),
                          ByVal after As _do(Of Boolean),
                          ByVal accept_null_ec As Boolean,
                          ByVal ParamArray cs() As _do(Of eventComb)) As eventComb
        Return eventComb.chain(before, after, accept_null_ec, cs)
    End Function

    Public Function chain(ByVal before As _do(Of Boolean),
                          ByVal cs() As _do(Of eventComb, Boolean),
                          ByVal after As _do(Of Boolean)) As eventComb
        Return eventComb.chain(before, cs, after)
    End Function

    Public Function chain(ByVal before As _do(Of Boolean),
                          ByVal after As _do(Of Boolean),
                          ByVal ParamArray cs() As _do(Of eventComb, Boolean)) As eventComb
        Return eventComb.chain(before, after, cs)
    End Function

    Public Function chain(ByVal ParamArray cs() As _do(Of eventComb, Boolean)) As eventComb
        Return eventComb.chain(cs)
    End Function

    Public Function chain(ByVal ParamArray cs() As _do(Of eventComb)) As eventComb
        Return eventComb.chain(cs)
    End Function

    Public Function chain(ByVal accept_null_ec As Boolean,
                          ByVal ParamArray cs() As eventComb) As eventComb
        Return eventComb.chain(accept_null_ec, cs)
    End Function

    Public Function chain(ByVal ParamArray cs() As eventComb) As eventComb
        Return eventComb.chain(cs)
    End Function

    Public Function chain(ByVal ParamArray cs() As void(Of eventComb, Boolean, Boolean, Boolean)) As eventComb
        Return eventComb.chain(cs)
    End Function

    Public Function as_predict(ByVal d As _do(Of Boolean)) As void(Of eventComb, Boolean, Boolean, Boolean)
        Return eventComb.as_predict(d)
    End Function

    Public Function as_eventComb(ByVal d As _do(Of eventComb),
                                 Optional ByVal accept_null_ec As Boolean = False) _
                                As void(Of eventComb, Boolean, Boolean, Boolean)
        Return eventComb.as_eventComb(d, accept_null_ec)
    End Function
End Module
